<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // const chunk = `data: {"id":"","object":"","created":0,"choices":[{"delta":{"content":""},"index":0,"finish_reason":null}]}
      //           data: {"id":"","object":"","created":0,"choices":[{"delta":{"content":"电"},"index":0,"finish_reason":null}]}
      //           data: {"id":"","object":"","created":0,"choices":[{"delta":{"content":"影"},"index":0,"finish_reason":null}]}
      //           data: {"id":"","object":"","created":0,"choices":[{"delta":{"content":"《"},"index":0,"finish_reason":null}]}`

      // const lines = chunk.split('data: ').slice(1)
      // const parsedLines = lines
      //   .map(line => line.trim()) // 去空格
      //   .filter(line => line !== '') // 去掉空行
      // console.log(parsedLines, typeof parsedLines) // 是一个object

      // for (const parsedLine of parsedLines) {
      //   if (parsedLine.includes('choices')) {
      //     const { choices } = JSON.parse(parsedLine)
      //     console.log(choices)
      //     const { delta } = choices[0]
      //     const { content } = delta
      //   }
      // }

      //           const chunk2 = `data:{"conversationId":"73186351-bbb7-4c32-a446-b462c43e1cbf","answer":"","reject":false,"hitType":"0","qas":[{"qaId":"5080b953fc5b4b29a98e9ef0053bf4e3","score":0.9350513,"content":"你可以做什么？","quoteType":"2"}],"fakeQa":[],"referenceSubdoc":[{"id":"5080b953fc5b4b29a98e9ef0053bf4e3","referenceType":0,"content":"你可以做什么？","score":0.9350513}],"answerType":"2","triggerSensitive":false,"questionType":"0","modelAnswer":true}

      //     data:{"conversationId":"73186351-bbb7-4c32-a446-b462c43e1cbf","answer":"你可以","reject":false,"hitType":"0","qas":[{"qaId":"5080b953fc5b4b29a98e9ef0053bf4e3","score":0.9350513,"content":"你可以做什么？","quoteType":"2"}],"fakeQa":[],"referenceSubdoc":[{"id":"5080b953fc5b4b29a98e9ef0053bf4e3","referenceType":0,"content":"你可以做什么？","score":0.9350513}],"answerType":"2","triggerSensitive":false,"questionType":"0","modelAnswer":true}

      //     data:{"conversationId":"73186351-bbb7-4c32-a446-b462c43e1cbf","answer":"你可以试试","reject":false,"hitType":"0","qas":[{"qaId":"5080b953fc5b4b29a98e9ef0053bf4e3","score":0.9350513,"content":"你可以做什么？","quoteType":"2"}],"fakeQa":[],"referenceSubdoc":[{"id":"5080b953fc5b4b29a98e9ef0053bf4e3","referenceType":0,"content":"你可以做什么？","score":0.9350513}],"answerType":"2","triggerSensitive":false,"questionType":"0","modelAnswer":true}
      //     `

      const chunk3 = `{"conversationId":"635fced4-aa19-4a23-9f0e-bad4a7050ffb","answer":"","reject":false,"hitType":"0","qas":[{"qaId":"5080b953fc5b4b29a98e9ef0053bf4e3","score":0.9350513,"content":"你可以做什么？","quoteType":"2"}],"fakeQa":[],"referenceSubdoc":[{"id":"5080b953fc5b4b29a98e9ef0053bf4e3","referenceType":0,"content":"你可以做什么？","score":0.9350513}],"answerType":"2","triggerSensitive":false,"questionType":"0","modelAnswer":true}
          {"conversationId":"635fced4-aa19-4a23-9f0e-bad4a7050ffb","answer":"你来","reject":false,"hitType":"0","qas":[{"qaId":"5080b953fc5b4b29a98e9ef0053bf4e3","score":0.9350513,"content":"你可以做什么？","quoteType":"2"}],"fakeQa":[],"referenceSubdoc":[{"id":"5080b953fc5b4b29a98e9ef0053bf4e3","referenceType":0,"content":"你可以做什么？","score":0.9350513}],"answerType":"2","triggerSensitive":false,"questionType":"0","modelAnswer":true}
          {"conversationId":"635fced4-aa19-4a23-9f0e-bad4a7050ffb","answer":"你来试试","reject":false,"hitType":"0","qas":[{"qaId":"5080b953fc5b4b29a98e9ef0053bf4e3","score":0.9350513,"content":"你可以做什么？","quoteType":"2"}],"fakeQa":[],"referenceSubdoc":[{"id":"5080b953fc5b4b29a98e9ef0053bf4e3","referenceType":0,"content":"你可以做什么？","score":0.9350513}],"answerType":"2","triggerSensitive":false,"questionType":"0","modelAnswer":true}
          {"conversationId":"635fced4-aa19-4a23-9f0e-bad4a7050ffb","answer":"你来试试不就","reject":false,"hitType":"0","qas":[{"qaId":"5080b953fc5b4b29a98e9ef0053bf4e3","score":0.9350513,"content":"你可以做什么？","quoteType":"2"}],"fakeQa":[],"referenceSubdoc":[{"id":"5080b953fc5b4b29a98e9ef0053bf4e3","referenceType":0,"content":"你可以做什么？","score":0.9350513}],"answerType":"2","triggerSensitive":false,"questionType":"0","modelAnswer":true}
          {"conversationId":"635fced4-aa19-4a23-9f0e-bad4a7050ffb","answer":"你来试试不就知道了","reject":false,"hitType":"0","qas":[{"qaId":"5080b953fc5b4b29a98e9ef0053bf4e3","score":0.9350513,"content":"你可以做什么？","quoteType":"2"}],"fakeQa":[],"referenceSubdoc":[{"id":"5080b953fc5b4b29a98e9ef0053bf4e3","referenceType":0,"content":"你可以做什么？","score":0.9350513}],"answerType":"2","triggerSensitive":false,"questionType":"0","modelAnswer":true}
`
      const result = chunk3
        // 1. 按换行符分割为数组
        .split('\n')
        // 2. 清理每行数据
        .map(line => {
          // 移除可能的SSE前缀和首尾空格
          const cleaned = line.replace(/^data:\s*/, '').trim()
          // 验证JSON格式（可选）
          try {
            JSON.parse(cleaned)
            return cleaned
          } catch (e) {
            console.warn('无效JSON数据:', cleaned)
            return null
          }
        })
        // 3. 过滤无效条目
        .filter(line => line && line.length > 0)
      console.log(result)
    </script>
  </body>
</html>
